package com.bmt.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * @author mickyfeng on 14-1-10.
 */
public class String_Utils extends StringUtils {
	public static boolean checkNotNullAndEmpty(String value) {
		return !(value == null || "".equals(value));
	}

	public static boolean checkNotNullAndSizeNotZero(ArrayList<Object> ob) {
		return !(ob == null || ob.size() <= 0);
	}

	public static boolean checkNotNullAndSizeNotZero(String[] ob) {
		return !(ob == null || ob.length <= 0);
	}

	public static String inSqlCondition(String[] ob) {
		String str = "''";
		if (checkNotNullAndSizeNotZero(ob)) {
			str = "'" + ob[0] + "'";
			for (int i = 1; i < ob.length; i++) {
				str += ",'" + ob[i] + "'";
			}
		}
		return str;
	}

	public static String inSqlConditionNoQuotationMark(String[] ob) {
		String str = "";
		if (checkNotNullAndSizeNotZero(ob)) {
			str = ob[0];
			for (int i = 1; i < ob.length; i++) {
				str += "," + ob[i];
			}
		}
		return str;
	}

	public static String listToStrings(List<String> list) {
		String str = "''";
		if (list != null && list.size() > 0) {
			str = "'" + list.get(0) + "'";
			for (int i = 1; i < list.size(); i++) {
				str += ",'" + list.get(i) + "'";
			}
		}
		return str;
	}

	public static String listToStringsNoQuotation(List<String> list) {
		String str = "";
		if (list != null && list.size() > 0) {
			str = list.get(0);
			for (int i = 1; i < list.size(); i++) {
				str += "," + list.get(i);
			}
		}
		return str;
	}

	public static boolean inList(List<String> list, String str) {
		if (str == null)
			return false;
		if (list != null) {
			for (String listVal : list)
				if (str.equals(listVal))
					return true;
		}
		return false;
	}

	public static boolean isLike(String str, String likeStr) {
		if (str == null || likeStr == null) {
			return false;
		}
		if (str.equals(likeStr))
			return true;
		likeStr = likeStr.replace("*", ".*").replace("?", ".?");
		return str.matches(likeStr);
	}

	public static boolean isNullOrEmpty(String str) {
		if (str == null || str.trim().equals("")) {
			return true;
		}
		return false;
	}

	public static boolean inArray(String[] array, String str) {
		if (str == null)
			return false;
		if (array != null) {
			for (String key : array) {
				if (str.equals(key))
					return true;
			}
		}
		return false;
	}

}
